﻿using MediatR;
using MS.Data.API.Write.Applicant.Command;
using MS.Data.Domain;
using MS.Data.ErrorCode;
using MS.Data.Infratructrue.Istanbul;

namespace MS.Data.API.Write.Applicant.CommandHandel
{

    public class XiuCommandHandel : IRequestHandler<XiuCommand, APIResult<int>>
    {
        IBaseRepository<Permission> perRep;

        public XiuCommandHandel(IBaseRepository<Permission> perRep)
        {
            this.perRep = perRep;
        }

        public async Task<APIResult<int>> Handle(XiuCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.code=APIEnum.更新成功;
            result.mes = APIEnum.更新成功.ToString();

            var res=perRep.GetAll().FirstOrDefault(s=>s.PermissionId==request.PermissionId);

            res.PermissionName = request.PermissionName;
            res.PermissionNo=request.PermissionNo;
            res.PermissionType=request.PermissionType;

            await perRep.Update(res);
            return await Task.FromResult(result);
        }
    }
}
